import { useEffect } from 'react';

/**
 * 键盘回车事件
 * @param callback
 */
export const useKeyDownEnter = (callback: () => void) => {
  const onKeyDown = (e: { keyCode: number }) => {
    if (e.keyCode === 13) {
      callback();
    }
  };

  useEffect(() => {
    document.addEventListener('keydown', onKeyDown);
    return () => {
      document.removeEventListener('keydown', onKeyDown);
    };
  }, []);
};
